home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ABUSESRC.ZIP / AbuseSrc / imlib / include / image.hpp < prev    next >
C/C++ Source or Header  |  1996-05-17  |  7KB  |  180 lines

  1. #ifndef _IMGAE_HPP_
  2. #define _IMGAE_HPP_
  3. #include <stdlib.h>
  4. #include "linked.hpp"
  5. #include "palette.hpp"
  6. #include "system.h"
  7. #include "specs.hpp"
  8. #define MAX_DIRTY 200
  9. #define Inew(pointer,type); { make_block(sizeof(type)); pointer=new type; }
  10.  
  11. extern char  *imerr_messages[];  // correspond to imERRORS
  12. #define imREAD_ERROR            1
  13. #define imINCORRECT_FILETYPE   2
  14. #define imFILE_CORRUPTED       3
  15. #define imFILE_NOT_FOUND       4
  16. #define imMEMORY_ERROR         5
  17. #define imNOT_SUPPORTED        6
  18. #define imWRITE_ERROR          7
  19. #define imMAX_ERROR            7
  20.  
  21. short current_error();
  22. void clear_errors();
  23. void set_error(short x);
  24. short last_error();
  25. void make_block(size_t size);
  26. void image_init();
  27. void image_uninit();
  28. extern linked_list image_list;
  29.  
  30.  
  31. class filter;
  32.  
  33.  
  34. class dirty_rect : public linked_node
  35. {
  36. public :
  37.   short dx1,dy1,dx2,dy2;
  38.   dirty_rect(short x1, short y1, short x2, short y2)
  39.   { dx1=x1; dy1=y1; dx2=x2; dy2=y2; 
  40.     if (x2<x1 || y2<y1) 
  41.       printf("add inccorect dirty\n");
  42.   }
  43.   virtual short compare(void *n1, short field)
  44.   { return ((dirty_rect *)n1)->dy1>dy1; }
  45. } ;
  46.  
  47. class image_descriptor
  48. {
  49.   short l,h;
  50.   short clipx1, clipy1, clipx2, clipy2;
  51. public :  
  52.   unsigned char keep_dirt,
  53.             static_mem;      // if this flag is set then don't free memory on exit
  54.   
  55.   linked_list dirties;
  56.   void *extended_descriptor;              // type depends on current system
  57.  
  58.   image_descriptor(short length, short height,
  59.           int keep_dirties=1, int static_memory=0);
  60.   short bound_x1(short x1)  { return x1<clipx1 ? clipx1 : x1; }
  61.   short bound_y1(short y1)  { return y1<clipy1 ? clipy1 : y1; }
  62.   short bound_x2(short x2)  { return x2>clipx2 ? clipx2 : x2; }
  63.   short bound_y2(short y2)  { return y2>clipy2 ? clipy2 : y2; }
  64.   short x1_clip() { return clipx1; }
  65.   short y1_clip() { return clipy1; }
  66.   short x2_clip() { return clipx2; }
  67.   short y2_clip() { return clipy2; }
  68.   void dirty_area(short x1, short y1, short x2, short y2) { ;}
  69.   void clean_area(short x1, short y1, short x2, short y2) { ; }
  70.   void clear_dirties();
  71.   short get_dirty_area(short &x1, short &y1, short &x2, short &y2) { return 0; }
  72.   void get_clip(short &x1, short &y1, short &x2, short &y2)
  73.     { x1=clipx1; y1=clipy1; x2=clipx2; y2=clipy2; }
  74.   void set_clip(short x1, short y1, short x2, short y2)
  75.     { if (x2<x1) x2=x1;
  76.       if (y2<y1) y2=y1;
  77.       if (x1<0) clipx1=0; else clipx1=x1;
  78.       if (y1<0) clipy1=0; else clipy1=y1;
  79.       if (x2>=l) clipx2=l-1; else clipx2=x2;
  80.       if (y2>=h) clipy2=h-1; else clipy2=y2;
  81.     }
  82.   void reduce_dirties();
  83.   void add_dirty(int x1, int y1, int x2, int y2);
  84.   void delete_dirty(int x1, int y1, int x2, int y2);
  85.   void resize(short length, short height)
  86.    { l=length; h=height; clipx1=0; clipy1=0; clipx2=l-1; clipy2=h-1; }
  87. } ;
  88.  
  89. class image : public linked_node
  90.   unsigned char *data;
  91.   short w,h;
  92.   void make_page(short width, short height, unsigned char *page_buffer);
  93.   void delete_page();
  94. public :
  95.   image_descriptor *special;
  96.   image(spec_entry *e, bFILE *fp);
  97.   image(bFILE *fp);
  98.   image(short width, short height,                 // required
  99.     unsigned char *page_buffer=NULL,
  100.     short create_descriptor=0);        // 0=no, 1=yes, 2=yes & keep dirties
  101.   unsigned char  pixel              (short x, short y);
  102.   void           putpixel           (short x, short y, char color);
  103.   unsigned char *scan_line          (short y) { return data+y*w; }
  104.   unsigned char *next_line          (short lasty, unsigned char *last_scan) 
  105.                                     { return last_scan+w; }          
  106.   long           total_pixels       (unsigned char background=0);
  107.   image         *copy               ();    // makes a copy of an image
  108.   void           clear              (short color=-1);  // -1 is background color
  109.   void           to_24bit           (palette &pal);
  110.   short          width              () { return (short)w; }
  111.   short          height             () { return (short)h; }
  112.   void           scroll             (short x1, short y1, short x2, short y2, short xd, short yd);
  113.   void           fill_image         (image *screen, short x1, short y1, short x2, short y2, 
  114.                      short allign=1);
  115.   void           put_image          (image *screen, short x, short y, char transparent=0);
  116.   void           put_part           (image *screen, short x, short y, short x1, short y1, 
  117.                      short x2, short y2, char transparent=0);
  118.   void           put_part_xrev      (image *screen, short x, short y, short x1, short y1, 
  119.                      short x2, short y2, char transparent=0);
  120.   void           put_part_masked    (image *screen, image *mask, short x, short y, 
  121.                      short maskx, short masky, short x1, short y1, short x2, short y2);
  122.   image         *copy_part_dithered (short x1, short y1, short x2, short y2);
  123.   void           bar                (short x1, short y1, short x2, short y2, unsigned char color);
  124.   void           xor_bar            (short x1, short y1, short x2, short y2, unsigned char color);
  125.   void              wiget_bar          (short x1, short y1, short x2, short y2, 
  126.                      unsigned char light, unsigned char med, unsigned char dark);
  127.   void           line               (short x1, short y1, short x2, short y2, unsigned char color);
  128.   void           rectangle          (short x1, short y1, short x2, short y2, unsigned char color);
  129.   void           burn_led           (short x, short y, long num, short color, short scale=1);
  130.   void           set_clip           (short x1, short y1, short x2, short y2);
  131.   void           get_clip           (short &x1,short &y1,short &x2,short &y2);
  132.   void           in_clip            (short x1, short y1, short x2, short y2);
  133.  
  134.   void           dirt_off           () { if (special && special->keep_dirt) special->keep_dirt=0; }
  135.   void           dirt_on            () { if (special) special->keep_dirt=1; }
  136.  
  137.   void           add_dirty          (int x1, int y1, int x2, int y2) 
  138.                                     { if (special) special->add_dirty(x1,y1,x2,y2); }
  139.   void           delete_dirty       (int x1, int y1, int x2, int y2) 
  140.                                     { if (special) special->delete_dirty(x1,y1,x2,y2); }
  141.   void           clear_dirties      () { if (special) special->clear_dirties(); }
  142.   void           dither             (palette *pal); // use a b&w palette!
  143.   void           resize             (short new_width, short new_height);
  144.   void           change_size        (short new_width, short new_height, unsigned char *page=NULL);
  145.   void           flood_fill         (short x, short y, unsigned char color);
  146.   image         *create_smooth      (short smoothness=1); // 0 no smoothness
  147.   void           unpack_scanline    (short line, char bitsperpixel=1);
  148.   unsigned char  brightest_color    (palette *pal);
  149.   void           flip_x              ();
  150.   void           flip_y             ();
  151.   void           make_color         (unsigned char color);
  152.   unsigned char  darkest_color      (palette *pal, short noblack=0);
  153.  
  154.   ~image();
  155. } ;
  156.  
  157.  
  158. class image_controller
  159. {
  160. public :
  161.   image_controller() { image_init(); }
  162.   ~image_controller()
  163.   { 
  164.      image_uninit(); 
  165.   }
  166. } ;
  167.  
  168.  
  169.  
  170. #endif
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.